﻿Imports SistemaINCA.Models

Namespace SistemaINCA
    Public Class ValidationsController
        Inherits System.Web.Mvc.Controller

        <AllowAnonymous()> _
        <HttpPost()> _
        Function Validate_Matricula_NIE(fieldId As String, fieldValue As String) As JsonResult
            Dim db As New SchoolClickDB_Repositorio
            Try
                Dim var = db.IMatricula.IsExistNIE(fieldValue)
                Return Json(New With {.fieldid = fieldId, .status = var}, JsonRequestBehavior.AllowGet)
            Catch ex As Exception
                Return Json(New With {.fieldid = fieldId, .status = True, .errorMsg = ex.Message}, JsonRequestBehavior.AllowGet)
            End Try
        End Function

        <AllowAnonymous()> _
        <HttpGet()> _
        Function Validate_Pais(frm_pais As String) As JsonResult
            Dim db As New SchoolClickDB_Repositorio
            Try
                If db.IDepartamentos.BuscarPais(frm_pais).Count = 1 Then
                    Return Json(True, JsonRequestBehavior.AllowGet)
                Else
                    Return Json("El país ingresado no existe en la base de datos", JsonRequestBehavior.AllowGet)
                End If
            Catch ex As Exception
                Return Json(ex.Message, JsonRequestBehavior.AllowGet)
            End Try
        End Function

        <AllowAnonymous()> _
        <HttpGet()> _
        Function Validate_CentroEscolar(frm_CEProcedencia As String) As JsonResult
            Dim db As New SchoolClickDB_Repositorio
            Try
                If db.IDepartamentos.BuscarCentroEscolar(frm_CEProcedencia).Count = 1 Then
                    Return Json(True, JsonRequestBehavior.AllowGet)
                Else
                    Return Json("El Centro Escolar de procedencia ingresado no existe en la base de datos", JsonRequestBehavior.AllowGet)
                End If
            Catch ex As Exception
                Return Json(ex.Message, JsonRequestBehavior.AllowGet)
            End Try
        End Function

        <AllowAnonymous()> _
        <HttpGet()> _
        Function Validate_Municipio(frm_Municipio As String, frm_DepartamentoID As Integer) As JsonResult
            Dim db As New SchoolClickDB_Repositorio
            Try
                If db.IDepartamentos.BuscarMunicipio(frm_DepartamentoID, frm_Municipio).Count = 1 Then
                    Return Json(True, JsonRequestBehavior.AllowGet)
                Else
                    Return Json("El municipio ingresado no existe en la base de datos o el municipio no pertenece al departamento seleccionado", JsonRequestBehavior.AllowGet)
                End If
            Catch ex As Exception
                Return Json(ex.Message, JsonRequestBehavior.AllowGet)
            End Try
        End Function
    End Class
End Namespace
